package cn.iocoder.yudao.module.worker.dal.mysql.clerkfans;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.worker.controller.app.clerkfans.vo.AppClerkFansPageReqVO;
import cn.iocoder.yudao.module.worker.dal.dataobject.clerkfans.ClerkFansDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.worker.controller.admin.clerkfans.vo.*;

/**
 * 店员关注 Mapper
 *
 * @author Jerry
 */
@Mapper
public interface ClerkFansMapper extends BaseMapperX<ClerkFansDO> {

    default PageResult<ClerkFansDO> selectPage(ClerkFansPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ClerkFansDO>()
                .eqIfPresent(ClerkFansDO::getWorkerClerkId, reqVO.getWorkerClerkId())
                .eqIfPresent(ClerkFansDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(ClerkFansDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ClerkFansDO::getId));
    }

    default PageResult<ClerkFansDO> selectPage(AppClerkFansPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ClerkFansDO>()
                .eqIfPresent(ClerkFansDO::getWorkerClerkId, reqVO.getWorkerClerkId())
                .eqIfPresent(ClerkFansDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(ClerkFansDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ClerkFansDO::getId));
    }

    default ClerkFansDO getClerkFans(Long userId, Long workerClerkId){
        return selectOne(new LambdaQueryWrapperX<ClerkFansDO>()
                .eqIfPresent(ClerkFansDO::getWorkerClerkId, workerClerkId)
                .eqIfPresent(ClerkFansDO::getUserId, userId));
    }

    default List<ClerkFansDO> getClerkFansList(Long userId, Set<Long> clerkIds){
        return selectList(new LambdaQueryWrapperX<ClerkFansDO>()
                .inIfPresent(ClerkFansDO::getWorkerClerkId, clerkIds)
                .eqIfPresent(ClerkFansDO::getUserId, userId));
    }

    default Integer getClerkFansCount(Long workerClerkId){
        return selectJoinOne(Integer.class, new MPJLambdaWrapperX<ClerkFansDO>()
                .selectCount(ClerkFansDO::getId)
                .eq(ClerkFansDO::getWorkerClerkId, workerClerkId));
    }
}